package org.springsecuritylearn.repository.dao;



import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.PagingAndSortingRepository;

import org.springsecuritylearn.repository.domain.Book;

import java.util.List;

public interface BookDao  extends JpaRepository<Book,Long>,JpaSpecificationExecutor<Book> {//关联表对象，主键类型

    //@EntityGraph(attributePaths = {"category"})
    @EntityGraph(value = "Book.fetch.category.and.author")
    List<Book> findByName(String name);


    @Query("select b from Book b where b.name  like ?1  and b.category.name=?2   order by  b.name desc")
    Page<Book>  findBooks(String bookName,String categoryName, Pageable sort);

    @Query("select count(b.id) from Book b where b.name  like ?1  and b.category.name=?2   order by  b.name desc")
    Page<Book>  findBookIDCount(String bookName,String categoryName, Pageable sort);


    @Query("update Book b  set b.name=?1  where b.id=?2")
    @Modifying
    int   updateOne(String bookName,Long id);


    @Query(value = "select * from rc_book  b  where b.rc_name=",nativeQuery = true)
    int   selectO(String bookName,Long id);
}
